package testGroovy

import groovy.json.JsonBuilder
import groovy.json.JsonSlurper

class FirstGroovy {

	private static final JSON = '''
		{
		    "pkgName": "optional",
		    "errorMsg": "您的车辆暂不能在网上投保!",
		    "resultCode": 1035,
		    "failRules": {
		        "all": {
		            "1": {
		                "autoAdjust": {
		                    "other": {},
		                    "normal": {
		                        "amount02": "300000"
		                    }
		                },
		                "ruleList": [
		                    {
		                        "context": "增加三者险，多数车主选30万",
		                        "direction": "+",
		                        "flowNo": "1",
		                        "flowType": "1",
		                        "groupNo": "1",
		                        "insuranceCode": "",
		                        "limitItems": [],
		                        "limitMax": -1,
		                        "limitMin": -1,
		                        "msg": "增加商业第三者责任险。",
		                        "operationTips": "amount02:*",
		                        "operationType": "A",
		                        "ruleCode": "AC103",
		                        "type": "B"
		                    },
		                    {
		                        "context": "增加三者险，多数车主选30万。或者您也可以自己添加盗抢险或司机乘客责任险。",
		                        "direction": "+",
		                        "flowNo": "1",
		                        "flowType": "1",
		                        "groupNo": "1",
		                        "insuranceCode": "",
		                        "limitItems": [],
		                        "limitMax": -1,
		                        "limitMin": -1,
		                        "msg": "增加其他险别，如商业第三者责任险、全车盗抢险等。",
		                        "operationTips": "amount02:*",
		                        "operationType": "A",
		                        "ruleCode": "AO101",
		                        "type": "B"
		                    },
		                    {
		                        "context": "增加三者险，多数车主选30万。或者您也可以自己添加盗抢险或司机乘客责任险。",
		                        "direction": "+",
		                        "flowNo": "1",
		                        "flowType": "1",
		                        "groupNo": "1",
		                        "insuranceCode": "",
		                        "limitItems": [],
		                        "limitMax": -1,
		                        "limitMin": -1,
		                        "msg": "增加其他险别，如商业第三者责任险、全车盗抢险等。",
		                        "operationTips": "amount02:*",
		                        "operationType": "A",
		                        "ruleCode": "AO106",
		                        "type": "B"
		                    }
		                ]
		            }
		        }
		    }
		}
	'''
	private static final bodyContent = '{"amount02": "0","amount03": "0"}'
	static main(args) {

		def root = new JsonSlurper().parseText(JSON)
		def body = [amount01:0, amount02:0.0, amount03:0, amount04:0.0, amount05:0.0, amount08:0, amount17:0.0, amount18:0, amount27:0, amount28:0, amount48:0, amount49:0, inputAmount:71400, amount41:0, amount57:0, amount50:0, amount59:0, pkgName:'11f']
		assert body instanceof Map
		
		def all = root.failRules.all
		assert all instanceof Map
		
		def result = all.collect { entry -> entry.value }
		println result
		def autoAdjust = result.autoAdjust
		assert autoAdjust.normal instanceof List
		assert autoAdjust.normal[0] instanceof Map
		def test = autoAdjust.normal.inject { prev,curr ->
			prev + curr
		}
		assert test instanceof Map
		
		println 'flag' + autoAdjust.normal[0]
		println autoAdjust.normal

		def d = autoAdjust.normal.collect { item ->
			[(item.key):item.value]
		}
		println d
		assert d == autoAdjust.normal
		def autoAdjustMap = autoAdjust.normal.inject { prev,curr ->
			prev + curr
		}.each { entry ->
			body.(entry.key) = entry.value 
		}
		println body
		def ruleList = result.ruleList
		def rules = ruleList.collect { entry -> entry }.inject { prev, curr ->
			prev + curr
		}
		def c = rules.each { entry ->
			def context = entry.context
			def msg = entry.msg
		}
		println c
		assert result instanceof List

		def map1 = [a:'1',b:'2']
		def map2 = [c:'3',d:'4']
		//		def list1 = [[1],[2],[3],[4],[5],[6],[7],[9]]
		def list = [map1, map2]
		println list
		def resutl1 = list.collect() { it }
		println resutl1.flatten()


		def a = []
		def b = ['a', 'b']
		println a += b
		if(a){
			println 'if'
			a+=b
		}else {
			println 'else'
			a = b
		}
		println a

		def h = []
		h.collect {
			1==1 ? '1' : ''
		}
	}
}
